<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<jsp:useBean id="dateObject" class="java.util.Date" scope="page"></jsp:useBean>


<html>
  <head>
    <base href="${pageContext.request.contextPath}/">
    <title>理陪单寻价管理</title>
    <%@ include file="../common/base.jsp" %>
   
    <script type="text/javascript">
        
    </script>

  </head>
  
  <body>
  	<!--head-->
	<div id="head">
		<jsp:include page="../common/head.jsp"></jsp:include>
	</div>
	<!--head end-->
	<!--container-->
	<div id="container">
		<div id="pageId" style="display: none;">02-10-01</div>
		<!--sidebar-->
		<jsp:include page="../common/menu.jsp"></jsp:include>
	    <!--sidebar-->
	    <!--main-->
	    <div class="main">
			<div class="location" style="background-position:22px -109px;">
				理陪单管理<span>&gt;</span>理陪单添加修理配件信息
			</div>
	        <!--content-->
			<div class="content">
				<table class="table_type1 tablesorter">
					<tr>
						<th style="text-align: left;">保单详细信息</th>
					</tr>

					<tr>
						<td>
							<table class="table_type1 tablesorter" style="align:left">
								<tr>
									<td>保单编码:${tAichePolicyDTO.id}</td>
									<td>保单是否在保:
										<c:if test="${tAichePolicyDTO.overStatus == 1}">是</c:if>
										<c:if test="${tAichePolicyDTO.overStatus != 1}">否</c:if>
									</td>
									<td>保单结束日期:
										<c:if test="${tAichePolicyDTO.overStatus == 1}">
											<jsp:setProperty property="time" name="dateObject" value="${tAichePolicyDTO.policyEndTime }"/>
											<fmt:formatDate value="${dateObject}" pattern="yyyy-MM-dd HH:mm:ss" />
										</c:if>
										<c:if test="${tAichePolicyDTO.overStatus != 1}">
											<jsp:setProperty property="time" name="dateObject" value="${tAichePolicyDO.policyOverTime }"/>
											<fmt:formatDate value="${dateObject}" pattern="yyyy-MM-dd HH:mm:ss" />
										</c:if>
									</td>
								</tr>
								<tr>
									<td>被保险人:${tAichePolicyDTO.userName}</td>
									<td>驾驶证车主:${tAichePolicyDTO.userName}</td>
									<td>行驶证车主:${tAichePolicyDTO.vehicleOwder}</td>
								</tr>
								<tr>
									<td>车牌号:${tAichePolicyDTO.vehiclePlateNo}</td>
									<td>厂牌型号:${tAichePolicyDTO.vehicleModel}</td>
									<td>VIN码:${tAichePolicyDTO.vehicleVin}</td>
								</tr>
								<tr>
									<td>发动机号:${tAichePolicyDTO.vehicleEngineNo}</td>
									<td>车架号:${tAichePolicyDTO.vehicleVin}</td>
									<td>车辆初次登记日:
										<jsp:setProperty property="time" name="dateObject" value="${tAichePolicyDO.vehicleIssueDate}"/>
										<fmt:formatDate value="${dateObject}" pattern="yyyy-MM-dd" />

									</td>
								</tr>
							</table>
						</td>
					</tr>

					<tr>
						<th style="text-align: left;">理陪单详细信息</th>
					</tr>

					<tr>
						<td>
							<table class="table_type1 tablesorter">
								<tr>
									<td>理陪单编码:${tAicheClaimDTO.id}<input type="hidden" id="claimId" name="claimId" value="${tAicheClaimDTO.id}"></td>
									<td>理陪单状态:
										<c:forEach var="item" items="${dictList}" varStatus="vatS">
											<c:if test="${item.enumCode == tAicheClaimDTO.status}">${item.enumName}</c:if>
										</c:forEach>
									</td>
									<td>理陪单完成时间:
										<jsp:setProperty property="time" name="dateObject" value="${tAicheClaimDTO.completeTime}"/>
										<fmt:formatDate value="${dateObject}" pattern="yyyy-MM-dd HH:mm:ss" />
									</td>
								</tr>
								<tr>
									<td>实际送车时间:
										<jsp:setProperty property="time" name="dateObject" value="${tAicheClaimDTO.actualSendTime}"/>
										<fmt:formatDate value="${dateObject}" pattern="yyyy-MM-dd HH:mm:ss" />
									</td>
									<td>预约送车开始时间:
										<jsp:setProperty property="time" name="dateObject" value="${tAicheClaimDTO.sendStartTime}"/>
										<fmt:formatDate value="${dateObject}" pattern="yyyy-MM-dd" />
									</td>
									<td>预约送车结束时间:
										<jsp:setProperty property="time" name="dateObject" value="${tAicheClaimDTO.sendEndTime}"/>
										<fmt:formatDate value="${dateObject}" pattern="yyyy-MM-dd" />
									</td>
								</tr>
							</table>
						</td>
					</tr>

					<tr>
						<th style="text-align: left;">平台修理配件信息&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
					</tr>
					<tr>
						<table class="table_type1 tablesorter">
							<thead>
								<tr>
									<th>配件名称</th>
									<th>配件报价</th>
									<th>配件拆装报价</th>
									<th>配件更换报价</th>
									<th>配件机修报价</th>
									<th>配件喷漆报价</th>
									<th>配件板金报价</th>
									<th>配件辅料报价</th>
									<th>配件焊接报价</th>
									<th>总报价</th>
								</tr>
							</thead>

							<tbody id="bodyResult">
								<c:if test="${orderType == 1}">
										<c:forEach var="item" items="${orderInfoList}" varStatus="vatS">
											<tr id="tr_${item.partsId}">
												<td>
													<input type="hidden" id="repairOrderId_${item.partsId}"  value="${item.repairOrderId}">
													<input type="hidden" id="partsId_${item.partsId}"  value="${item.partsId}">
													<input type="hidden" id="id_${item.partsId}"  value="${item.id}">
													<input type="hidden" id="partsName_${item.partsId}" value="${item.partsName}">
													${item.partsName}
												</td>
												<td><input type="text" id="pfPartsPrice_${item.partsId}"
														   name="price_${item.partsId}"  value="${item.pfPartsPrice}"
														   onblur="calculateOffer('pfPartsPrice_','${item.partsId}')">
												</td>
												<td><input type="text" id="pfDisassemblyPrice_${item.partsId}"
														   name="price_${item.partsId}"  value="${item.pfDisassemblyPrice}"
														   onblur="calculateOffer('pfDisassemblyPrice_','${item.partsId}')">
												</td>
												<td><input type="text" id="pfReplacePrice_${item.partsId}"
														   name="price_${item.partsId}"  value="${item.pfReplacePrice}"
														   onblur="calculateOffer('pfReplacePrice_','${item.partsId}')">
												</td>
												<td><input type="text" id="pfMechanicPrice_${item.partsId}"
														   name="price_${item.partsId}"  value="${item.pfMechanicPrice}"
														   onblur="calculateOffer('pfMechanicPrice_','${item.partsId}')">
												</td>
												<td><input type="text" id="pfPaintPrice_${item.partsId}"
														   name="price_${item.partsId}"  value="${item.pfPaintPrice}"
														   onblur="calculateOffer('pfPaintPrice_','${item.partsId}')">
												</td>
												<td><input type="text" id="pfSheetmetaPrice_${item.partsId}"
														   name="price_${item.partsId}"  value="${item.pfSheetmetaPrice}"
														   onblur="calculateOffer('pfSheetmetaPrice_','${item.partsId}')">
												</td>
												<td><input type="text" id="pfAccessoriesPrice_${item.partsId}"
														   name="price_${item.partsId}"  value="${item.pfAccessoriesPrice}"
														   onblur="calculateOffer('pfAccessoriesPrice_','${item.partsId}')">
												</td>
												<td><input type="text" id="pfWeldingPrice_${item.partsId}"
														   name="price_${item.partsId}"  value="${item.pfWeldingPrice}"
														   onblur="calculateOffer('pfWeldingPrice_','${item.partsId}')">
												</td>
												<td><input type="text" id="platformOffer_${item.partsId}"
														   name="platformOffer" value="${item.platformOffer}" readonly>
												</td>
											</tr>
										</c:forEach>
								</c:if>
							</tbody>
							<tr>
								<td colspan="9" style="text-align: left">平台修理总价</td>
								<td colspan="1"><span id="repairPlatformOffer">${tRepairOrderDTO.platformOffer}</span></td>
							</tr>
						</table>
					</tr>

					<tr>
						<th style="text-align: left;">用户修理配件信息&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
					</tr>
					<tr>
						<table class="table_type1 tablesorter">
							<thead>
								<tr>
									<th>配件名称</th>
									<th>配件报价</th>
									<th>配件拆装报价</th>
									<th>配件更换报价</th>
									<th>配件机修报价</th>
									<th>配件喷漆报价</th>
									<th>配件板金报价</th>
									<th>配件辅料报价</th>
									<th>配件焊接报价</th>
									<th>总报价</th>
								</tr>
							</thead>

							<tbody>
								<c:if test="${orderType == 1}">
									<c:forEach var="item" items="${orderInfoList}" varStatus="vatS">
										<tr>
											<td>${item.partsName}</td>
											<td><input type="text" id="userPartsPrice_${item.partsId}"
													   name="userPrice_${item.partsId}"  value="${item.userPartsPrice}"
													   onblur="calculateUserOffer('userPartsPrice_','${item.partsId}')">
											</td>
											<td><input type="text" id="userDisassemblyPrice_${item.partsId}"
													   name="userPrice_${item.partsId}"  value="${item.userDisassemblyPrice}"
													   onblur="calculateUserOffer('userDisassemblyPrice_','${item.partsId}')">
											</td>
											<td><input type="text" id="userReplacePrice_${item.partsId}"
													   name="userPrice_${item.partsId}"  value="${item.userReplacePrice}"
													   onblur="calculateUserOffer('userReplacePrice_','${item.partsId}')">
											</td>
											<td><input type="text" id="userMechanicPrice_${item.partsId}"
													   name="userPrice_${item.partsId}"  value="${item.userMechanicPrice}"
													   onblur="calculateUserOffer('userMechanicPrice_','${item.partsId}')">
											</td>
											<td><input type="text" id="userPaintPrice_${item.partsId}"
													   name="userPrice_${item.partsId}"  value="${item.userPaintPrice}"
													   onblur="calculateUserOffer('userPaintPrice_','${item.partsId}')">
											</td>
											<td><input type="text" id="userSheetmetaPrice_${item.partsId}"
													   name="userPrice_${item.partsId}"  value="${item.userSheetmetaPrice}"
													   onblur="calculateUserOffer('userSheetmetaPrice_','${item.partsId}')">
											</td>
											<td><input type="text" id="userAccessoriesPrice_${item.partsId}"
													   name="userPrice_${item.partsId}"  value="${item.userAccessoriesPrice}"
													   onblur="calculateUserOffer('userAccessoriesPrice_','${item.partsId}')">
											</td>
											<td><input type="text" id="userWeldingPrice_${item.partsId}"
													   name="userPrice_${item.partsId}"  value="${item.userWeldingPrice}"
													   onblur="calculateUserOffer('userWeldingPrice_','${item.partsId}')">
											</td>
											<td><input type="text" id="userOffer_${item.partsId}"
													   name="userOffer" value="${item.userOffer}" readonly>
											</td>
										</tr>
									</c:forEach>
								</c:if>
								<tr>
									<td colspan="9" style="text-align: left">用户修理总价</td>
									<td colspan="1"><span id="repairUserOffer">${tRepairOrderDTO.userOffer}</span></td>
								</tr>
							</tbody>
						</table>
					</tr>
				</table>

				<br/>
				<div class="button_wrap">
					<c:if test="${tAicheClaimDTO.status == 8}">
						<a href="javascript:void(0);" onClick="saveInfo();"  class="bg_green">提交</a>
					</c:if>
					<input type="button" value="关闭" onclick="closeClaimDetail()" >
				</div>

			</div>
	        <!--content-->

			<!--foot-->
			<%@ include file="../common/foot.jsp" %>
			<!--foot-->
		    </div>
		</div>
	    <!--main-->
	</div>
	<!--container-->
	<script src="${pageContext.request.contextPath}/static/js/basic.js"></script>
	<script type="text/javascript">
		function saveInfo(){
            var claimId = $("#claimId").val();
            var repairPlatformOffer = $("#repairPlatformOffer").text();
            var repairUserOffer = $("#repairUserOffer").text();

            $.ajax({
                type: "POST",
                url: "${pageContext.request.contextPath}/claim/updateRepairOrderInfo",
                dataType:"json",
                data: {
                    "dataJson":JSON.stringify(getParams()),
                    "claimId":claimId,
                    "repairPlatformOffer":repairPlatformOffer,
					"repairUserOffer":repairUserOffer
                },
                success: function(data){
                    if (data.errorCode==0) {
                        prompt.alert("添加修理配件信息成功！");

                        setTimeout(function(){
                            window.location.href = "${pageContext.request.contextPath}/claim/showClaim";
                        },2000);
                    }else{
                        prompt.alert(data.msg);
                    }
                }
            });
		}

        //获取form表单所有参数
        function getParams(){
            var list = [];
            $("#bodyResult tr").each(function(i,e){
                var json = {};
                var id = $(this).attr("id").replace("tr_","");
                var orderId= $("#id_"+id).val();
                json["id"] = orderId;
                var partsId= $("#partsId_"+id).val();
                json["partsId"] = partsId;
                var partsName =$("#partsName_"+id).val();
                json["partsName"] = partsName;
                var plaformOffer = $("#plaformOffer_"+id).val();
                json["plaformOffer"] = plaformOffer;
                var userOffer = $("#userOffer_"+id).val();
                json["userOffer"] = userOffer;
                var repairOrderId = $("#repairOrderId_"+id).val();
                json["repairOrderId"] = repairOrderId;


                $("input[name='price_"+id+"']").each(function(){
                    var pid = ($(this).attr("id")).replace("_"+id,"");
                    var val = $(this).attr("value");
                    //alert("pid="+pid+"-----val="+val);
                    json[pid] = val;
                });

                $("input[name='userPrice_"+id+"']").each(function(){
                    var pid = ($(this).attr("id")).replace("_"+id,"");
                    var val = $(this).attr("value");
                    //alert("pid="+pid+"-----val="+val);
                    json[pid] = val;
                });
                list[i] = json;
			});

            return list;
        }

		function closeClaimDetail(){
            window.location.href = "${pageContext.request.contextPath}/claim/showClaim";
		}

		function calculateOffer(name,id){
			var cval = $("#"+name+id).val();
            //纯数字正则
            var reg = new RegExp("^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$");
            if(cval !=0 && !reg.test(cval)){
                prompt.alert("请输入有效的报价");
                return false;
            }
            var plaformOffer=0;
            $("input[name='price_"+id+"']").each(function(){
                var price = $(this).val();
				plaformOffer = plaformOffer+parseFloat(price);
			});
            $("#plaformOffer_"+id).val(plaformOffer);

            var repairPlatformOffer = 0;
            $("input[name='platformOffer']").each(function(){
                var price = $(this).val();
                repairPlatformOffer = repairPlatformOffer+parseFloat(price);
            });
            $("#repairPlatformOffer").text(repairPlatformOffer);

		}

        function calculateUserOffer(name,id){
            var cval = $("#"+name+id).val();
            //纯数字正则
            var reg = new RegExp("^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$");
            if(cval !=0 && !reg.test(cval)){
                prompt.alert("请输入有效的报价");
                return false;
            }
            var plaformOffer=0;
            $("input[name='userPrice_"+id+"']").each(function(){
                var price = $(this).val();
                plaformOffer = plaformOffer+parseFloat(price);
            });
            $("#userOffer_"+id).val(plaformOffer);

            var repairUserOffer = 0;
            $("input[name='userOffer']").each(function(){
                var price = $(this).val();
                repairUserOffer = repairUserOffer+parseFloat(price);
            });
            $("#repairUserOffer").text(repairUserOffer);

        }

	</script>
  </body>
</html>
